<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>计算属性和assign的使用</title>
</head>
<body>
    <script>
        let hd = {};
        let name = "name";
        hd[name] = "xiaxia";
        console.log(hd);


        let hdr = {};
        let id = 0;
        hdr[`id${id++}`] = id;
        hdr[`id${id++}`] = id;
        hdr[`id${id++}`] = id;
        hdr[`id${id++}`] = id;
        console.log(hdr);



        let lessons = [
            {
                name : 'html',
                price : 99
            },
            {
                name : 'css',
                price : 88
            },
            {
                name : 'js',
                price : 199
            }
        ];
        let newObj = lessons.reduce((obj,cur,index) => {
            obj[`${cur[name]}-idx${index}`] = cur; 
            return obj;
        },{});
        console.log(JSON.stringify(newObj,null,2));



        // Object.assign()方法，将两个对象合并
        let mm = {name : "xiasnn"};
        let nn = {price : 99};
        let kk = Object.assign(mm,nn);
        console.log(JSON.stringify(kk,null,2));



        function upload(param){
            let options = {
                size : 66
            };
            // 后面的优先级高
            options = Object.assign(options,param);
            return options;
        }

        console.log(upload({size:99,price:199}));
    </script>
</body>
</html>